from typing import List
class Solution:
    def longestSubarray(self, nums: List[int]) -> int:
        n = len(nums)
        if n == 1:
            return 1

        suf = [0] * n
        suf[-1] = 1
        ans = 2
        for i in range(n - 2, 0, -1):
            if nums[i] <= nums[i + 1]:
                suf[i] = suf[i + 1] + 1
                ans = max(ans, suf[i] + 1)  # 把 nums[i-1] 拼在 suf[i] 前面
            else:
                suf[i] = 1

        pre = 1
        for i in range(1, n - 1):
            if nums[i - 1] <= nums[i + 1]:
                ans = max(ans, pre + 1 + suf[i + 1])  # 替换 nums[i]
            if nums[i - 1] <= nums[i]:
                pre += 1
                ans = max(ans, pre + 1)  # 把 nums[i+1] 拼在 pre 后面
            else:
                pre = 1
        return ans

